package org.zpmis.domain.order.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.zpmis.domain.order.model.Order;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OrderListVo {

    private Long id;
    /**
     * 订单号
     */
    private String orderNumber;
    /**
     * 申请日期
     */
    private String applyTime;

    /**
     * 申请企业id  关联企业表id   company表的id
     */
    private Long companyId;

    /**
     * 申请企业类型
     */
    private String applyCompanyType;

    /**
     * 申请服务类型 1追溯服务  2追溯设备
     */
    private Integer applyServiceType;

    /**
     * 申请订单备注
     */
    private String applyRemark;

    /**
     * 申请数量
     */
    private Integer applyNumber;

    /**
     * 申请类型 1设备类型 2标签类型
     */
    private Integer applyType;

    /**
     * 申请规格
     */
    private Integer applySpecs;

    /**
     * 工艺材质
     */
    private Integer craftMaterial;

    /**
     * 单价
     */
    private String unitPrice;

    /**
     * 总价
     */
    private String totalPrice;

    /**
     * 开票类型
     */
    private Integer invoiceType;

    /**
     * 开票企业名称
     */
    private String invoiceCompanyName;

    /**
     * 纳税人识别号
     */
    private String invoiceTaxpayerIdentiNumber;

    /**
     * 开户银行
     */
    private String bankName;

    /**
     * 开户名
     */
    private String bankAccountName;

    /**
     * 开户账号
     */
    private String bankAccount;

    /**
     * 开票地址
     */
    private String invoiceAddress;

    /**
     * 开票电话
     */
    private String invoiceMobile;

    /**
     * 收货人
     */
    private String consignee;

    /**
     * 收货地址
     */
    private String takeDeliveryAdress;

    /**
     * 收货人电话
     */
    private String taskDeliveryMobile;

    /**
     * 订单状态 0 待审核 1 待发货 2 已发货 3 已签收 4 已拒绝
     */
    private Integer status;

    /**
     * 收款状态 0未收款 1已收款
     */
    private Integer collectionStatus;

    /**
     * 收款人
     */
    private String collection;

    /**
     * 收款时间
     */
    private String collectionTime;

    /**
     * 记录创建时间
     */
    private String createTime;

    /**
     * 记录修改时间
     */
    private String updateTime;

    /**
     * 订单备注
     */
    private String remark;

    /**
     * 开始码段
     */
    private String startNumber;
    /**
     * 结束码段
     */
    private String endNumber;

    /**
     * 补废数量
     */
    private Integer repairNumber;

    /**
     * 收款方式  1先付款 2后付款 3周期付款
     */
    private Integer collectionType;

    /**
     * 申请企业名称
     */
    private String companyName;

    /**
     * 物流单号
     */
    private String logisticsNum;

    /**
     * 分享文件
     */
    private String shareAttachment;

    /**
     * 附件图片
     */
    private String attachmentImage;

    /**
     * 回执单附件
     */
    private String receiptAttachment;

    /**
     * 代理企业id
     */
    private Long agentCompanyId;

    /**
     * 代理企业名称
     */
    private String agentCompanyName;
    /**
     * 订单明细集合
     */
    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    private List<OrderDetailVo> orderDetailVoList;

    public OrderListVo(Order order) {
        this.id = order.getId();
        this.orderNumber = order.getOrderNumber();
        this.applyTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(order.getApplyTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.companyId = order.getCompanyId();
        this.applyCompanyType = order.getApplyCompanyType();
        this.applyServiceType = order.getApplyServiceType();
        this.applyNumber = order.getApplyNumber();
        this.applyType = order.getApplyType();
        this.applySpecs = order.getApplySpecs();
        this.craftMaterial = order.getCraftMaterial();
        this.unitPrice = order.getUnitPrice() == null ? "0" : order.getUnitPrice().toString();
        this.totalPrice = order.getTotalPrice() == null ? "0" : order.getTotalPrice().toString();
        this.invoiceType = order.getInvoiceType();
        this.invoiceCompanyName = order.getInvoiceCompanyName();
        this.invoiceTaxpayerIdentiNumber = order.getInvoiceTaxpayerIdentiNumber();
        this.bankName = order.getBankName();
        this.bankAccountName = order.getBankAccountName();
        this.bankAccount = order.getBankAccount();
        this.invoiceAddress = order.getInvoiceAddress();
        this.invoiceMobile = order.getInvoiceMobile();
        this.consignee = order.getConsignee();
        this.takeDeliveryAdress = order.getTakeDeliveryAdress();
        this.taskDeliveryMobile = order.getTaskDeliveryMobile();
        this.status = order.getStatus();
        this.collectionStatus = order.getCollectionStatus();
        this.collection = order.getCollection();
        this.collectionTime = order.getCollectionTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(order.getCollectionTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.createTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(order.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));;
        this.updateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(order.getUpdateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));;
        this.remark = order.getRemark();
        this.startNumber = order.getStartNumber();
        this.endNumber = order.getEndNumber();
        this.repairNumber = order.getRepairNumber();
        this.collectionType = order.getCollectionType();
        this.applyRemark = order.getApplyRemark();
        this.logisticsNum = order.getLogisticsNum();
        this.shareAttachment = order.getShareAttachment();
        this.attachmentImage = order.getAttachmentImage();
        this.receiptAttachment = order.getReceiptAttachment();
        this.agentCompanyId = order.getAgentCompanyId();
    }
}
